import { Component } from '@angular/core';
import { NzMenuModule } from 'ng-zorro-antd/menu';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { MenuDto } from '../../interfaces/menu-dto';
import { MenuApi } from '../../service/menu.api';

@Component({
  selector: 'app-hrp-bar-items',
  standalone: true,
  imports: [NzMenuModule, NzIconModule],
  templateUrl: './hrp-bar-items.component.html',
  styleUrl: './hrp-bar-items.component.less'
})
export class HrpBarItemsComponent {
  selectedNode?: MenuDto

  barItems: MenuDto[] = []

  constructor(private menuApi: MenuApi) {
    const applicationId = 'hrp-bar', hospId = '', tenantId = '';
    this.menuApi.getApplicationMenus(applicationId, hospId, tenantId).subscribe(el => {
      if (el.code === 200 && Array.isArray(el.data)) {

        this.barItems = el.data.map(item => {
          return {
            id: item.id,
            title: item.title,
            icon: item.icon,
            href: item.href,
            parentId: item.parentId,
            children: item.children ?? [],
          } as MenuDto
        })

      }
    });
  }

  itemClick(item: MenuDto) {
    this.selectedNode = item;
  }
}
